package com.kh.pajx.sop.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.base.BaseServiceImpl;
import com.kh.pajx.sop.dao.ISysUserGroupDao;
import com.kh.pajx.sop.domain.PageBean;
import com.kh.pajx.sop.domain.SysUserGroup;
import com.kh.pajx.sop.service.ISysUserGroupService;
import com.kh.pajx.sop.util.page.QueryHelper;

/**
 * 用户组信息业务逻辑实现类
 * @author:	azzcsimp
 * @Createdate:	2014年7月17日 下午8:20:50
 */
@Service
@Transactional
public class SysUserGroupServiceImpl extends BaseServiceImpl<SysUserGroup>
		implements ISysUserGroupService {

	@Resource
	private ISysUserGroupDao sysUserGroupDao;
	
	@Override
	public void save(SysUserGroup sysUserGroup) {
		sysUserGroup.setUsgCode(getUsgCode());
		sysUserGroupDao.save(sysUserGroup);
	}

	/**
	 * 获取当前用户组的编码
	 * @see com.kh.pajx.sop.service.ISysUserGroupService#getUsgCode()
	 */
	@Override
	public String getUsgCode() {
		String usgCode = sysUserGroupDao.getMaxUsgCode();
		if (StringUtils.isNotEmpty(usgCode)) {
			return (Integer.parseInt(usgCode) + 100) + "";
		} else{
			return "1000";
		}
	}
	
	/**
	 * 分页获取用户组列表
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#getPageBean(int, int, com.kh.pajx.sop.util.page.QueryHelper)
	 */
	@Override
	public PageBean getPageBean(int pageNum, int pageSize,
			QueryHelper queryHelper) {
		return sysUserGroupDao.getPageBean(pageNum, pageSize, queryHelper);
	}
	
	/**
	 * 根据uuid获取用户组对象
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#getById(java.lang.String)
	 */
	@Override
	public SysUserGroup getById(String uuid) {
		return sysUserGroupDao.getById(uuid);
	}
	
	/**
	 * 更新用户组信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#update(java.lang.Object)
	 */
	@Override
	public void update(SysUserGroup demo) {
		sysUserGroupDao.update(demo);
	}
	
	/**
	 * 删除用户组信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#delete(java.lang.String)
	 */
	@Override
	public void delete(String uuid) {
		sysUserGroupDao.delete(uuid);
	}
	
	/**
	 * 获取用户组列表
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#findAll()
	 */
	@Override
	public List<SysUserGroup> findAll() {
		return sysUserGroupDao.findAll();
	}
}
